<?php
/**
 * Project:     WebATS Manager
 * File:        Template.class.php
 * SVN:         $Id: $
 */
class Template extends CI_Controller {
	private $words;
	public function __construct()
	{
		$this->_ci =& get_instance();
	}

	public function SetKeywords($Setkeyword, $Setvalue){
			if(gettype($this->words) != 'array'){
				$this->words = array();
			}
			$array = array($Setkeyword => $Setvalue);
			$this->words = array_merge($array,$this->words);
		}
	public function ReplaceKeywords($maskContent) {
		if($this->words){
			if(!$maskContent || strlen($maskContent) == 0)
				return $maskContent;
			
			foreach($this->words as $keyword=>$value)
			{
				$keyword = $this->_ci->config->item('open_bracket').$keyword.$this->_ci->config->item('close_bracket');
				$maskContent = str_replace($keyword, $value, $maskContent);
			}
			return $maskContent;
		}
		else
		{ 
		return false; 
		}
	}
	public function GetReplaceKeywordCount($maskContent){
				if(!$maskContent || strlen($maskContent) == 0)
					return $maskContent;
				$count = array();
				foreach($this->words as $keyword=>$value){
					$searchWord = $this->_ci->config->item('open_bracket').$keyword.$this->_ci->config->item('close_bracket');
					$wordCount = substr_count($maskContent, $searchWord);
					if($wordCount > 0)
						$count[$keyword] = $wordCount;
				}
				return $count;
		}
}

?>